#include <XrdDownloadManagerLog.hh>

#include "XrdDownloadManagerBase.hh"

XrdDownloadManagerBase::XrdDownloadManagerBase() :
        fLogDM ( 0 ),
        fDoXrdcpInLogFile ( false ),
        fLogDirectory ( "/tmp" ),
        fCurrentLogFileName ( "" ),
        fRemoveLogAfterSuccessCopy ( true ),
        fRemoveLogDirectoryAfterSuccessCopy ( false ),
        fRandomizeFilelist (false),
        fFileNameFrom ( "" ),
        fFileNameTo ( "" ),
        fDoAuthenticate ( false ),
        fSourceTypes ( "std" ),
        fGlobalRedirectorName ( "" ),
        fXrdcpCmd ( XROOTD_XRDCP_CMD ),
        fXrdcpCmdOptions ( "" ),
        fXrdcpCmdCn ( "" ),
        fXrdcpCmdRoot( ROOT_EXE ),
        fXrdcpCmdRootMacro(""),
        fDoZipTest ( false ),
        fZipCmd ( XRDDM_ZIP ) {
    fDoZipTest = true ;
//         fSourceTypes = "std,gr1";
}

XrdDownloadManagerBase::~XrdDownloadManagerBase() {
    delete fLogDM;
}

int XrdDownloadManagerBase::DoAuthenticate ( bool showProcess ) {
    XrdDMLogDebugFull ( "virtual Authenticate %d" ,showProcess );
    return 0;
}

int XrdDownloadManagerBase::DoCopy ( string from, string to ) {

    fFileNameFrom = from;
    fFileNameTo = to;

//     InitLogFile();

    if ( DoCopyPre ( fFileNameFrom.c_str(),fFileNameTo.c_str() ) ) return 1;

    XrdDMLogDebugFull ( "DoCopy : %s %s %s",XrdCpCmd().c_str(),from.c_str(),to.c_str() );

    if ( fSourceTypes.empty() ) {
        fSourceTypes = "std";
    }

    int retValCp = 0;

    vector<string> sourcetypes;
    char * pch;
    string tmp;
    XrdDMLogDebugSilent ( "Sources types are '%s' ...",fSourceTypes.c_str() );
    pch = strtok ( ( char* ) fSourceTypes.c_str(),"," );
    while ( pch != NULL ) {
        tmp = pch;
        sourcetypes.push_back ( tmp );
        pch = strtok ( NULL, "," );
    }
//     XrdDMLogDebugSilent ( "Number of Sources types are '%d' ...",sourcetypes.size());
    unsigned int ii;
    for ( ii=0; ii < sourcetypes.size(); ii++ ) {
        XrdDMLogDebugSilent ( "[%s] %s %s ",sourcetypes[ii].c_str(),from.c_str(),to.c_str() );

        retValCp = DoCopyWithType ( GetInputTypeId ( sourcetypes[ii].c_str() ),from,to );
        // in case copy was ok break loop
        XrdDMLogDebugSilent ( "retValCp %d",retValCp );

        // in case file copy was ok break
        if ( !retValCp ) break;
        
        // in case error (ret is > 100)
        if (retValCp > 100 ) break;
    }

    if ( DoCopyPost ( fFileNameFrom,fFileNameTo ) ) return 3;


    if ( !retValCp )
        RemovingCopyProcessLogFile();

    XrdDMLogDebugSilent ( "DoCopy : retrun retValCp %d",retValCp );

    return retValCp;
}
void XrdDownloadManagerBase::GenerateRandomNumbers ( unsigned int* num,const unsigned int size ) {

    unsigned int ii,jj,tmp;
    bool found=true;
    srand ( time ( NULL ) );
    for ( ii=0; ii < size; ii++ ) {
        if ( !ii ) {
            num[ii] = rand() % size;
            continue;
        }
        found = true;
        while ( found ) {
            found = false;
            tmp = rand() % size;
            for ( jj=0;jj<ii;jj++ ) if ( num[jj] == tmp ) found = true;
            if ( !found ) num[ii] = tmp;
        }

    }
}


int XrdDownloadManagerBase::DoCopyStd ( string from, string to ) {
    const unsigned int sizeOfList = fListOfFileNamesFrom.size();
    if ( !sizeOfList ) {
//         XrdDMLogGWarning( "No files found in catalogue from file '%s' !!!!!!",fFileNameFrom.c_str() );
        XrdDMLogWarning( "No files found in catalogue from file '%s' !!!!!!",fFileNameFrom.c_str() );
        return 10;

    }

    XrdDMLogDebugFull ( "XrdDownloadManagerBase::DoCopy -> Number of input files : %d",sizeOfList );
//     srand ( time(NULL) );
    unsigned int rndNums[sizeOfList];
    unsigned int ii,retValCpStd;

    GenerateRandomNumbers ( &rndNums[0],sizeOfList );

    for ( ii=0; ii < sizeOfList; ii++ ) {
        XrdDMLogDebugFull ( "XrdDownloadManagerBase::DoCopy -> Copying index %d(%d) with filename '%s'",ii,rndNums[ii],fListOfFileNamesFrom[rndNums[ii]].c_str() );
        retValCpStd = DoXrdCp ( fListOfFileNamesFrom[rndNums[ii]].c_str(),fFileNameTo.c_str() );

        // we will test zip file (if it is zip) and if file is ok then we break loop
        if ( ( !TestZipFile ( from,to ) ) && !retValCpStd ) {
            
            XrdDMLogDebugSilent ( "DoCopyStd : retrun retValCpStd %d",retValCpStd );
            retValCpStd = 0;
            return retValCpStd;
        }
        retValCpStd = 1;
    }

    XrdDMLogDebugSilent ( "DoCopyStd : retrun retValCpStd %d",retValCpStd );
    return retValCpStd;
}

int XrdDownloadManagerBase::DoCopyStdGR ( string from, string to ) {
    int sizeOfList = fListOfFileNamesFromGR.size();
    if ( !sizeOfList ) {
//         XrdDMLogGWarning ( "GR: No files found in catalogue from file '%s' !!!!!!",fFileNameFrom.c_str() );
        XrdDMLogWarning ( "GR: No files found in catalogue from file '%s' !!!!!!",fFileNameFrom.c_str() );
        return 10;
    }

    XrdDMLogDebugFull ( "XrdDownloadManagerBase::DoCopy -> Number of input files : %d",sizeOfList );

    unsigned int ii,retValCpStd=1;
    for ( ii=0; ii < fListOfFileNamesFromGR.size(); ii++ ) {
        XrdDMLogDebugFull ( "XrdDownloadManagerBase::DoCopyStdGR -> Copying index %d with filename '%s'",ii,fListOfFileNamesFromGR[ii].c_str() );
        retValCpStd = DoXrdCp ( fListOfFileNamesFromGR[ii],fFileNameTo );

        // we will test zip file (if it is zip) and if file is ok then we break loop
        if ( ( !TestZipFile ( from,to ) ) && !retValCpStd ) {
            retValCpStd = 0;
            break;
        }
        retValCpStd = 1;

    }

    XrdDMLogDebugSilent ( "DoCopyStdGR : retrun retValCpStd %d",retValCpStd );
    return retValCpStd;
}

int XrdDownloadManagerBase::DoCopyStdROOT(string from, string to)
{
    unsigned int retValCpStd=0;
    XrdDMLogDebugFull( "DoCopyStdROOT : %s %s",from.data(),to.data());

    if (fXrdcpCmdRoot.empty()) return 1;
    
    if (fXrdcpCmdRootMacro.empty()) {
        XrdDMLogWarning ( "DoCopyStdROOT : fXrdcpCmdRootMacro is empty !!! Skipping Copy by ROOT macro ..." );
        return 2;
        
    }
    
    string redirectTo;
    if ( ( !fCurrentLogFileName.empty() ) && ( fLogDM ) ) {
        redirectTo.append ( " >> " );
        redirectTo.append ( fCurrentLogFileName.c_str() );
        redirectTo.append ( " 2>&1" );
    }
    
    // check if root.exe exitsts
    string cmd="ls ";
    cmd.append(fXrdcpCmdRoot.data());
    cmd.append ( redirectTo.c_str() );
    if (system(cmd.data())) return 3;
    
    // here check if macro exist
    cmd="ls ";
    cmd.append(fXrdcpCmdRootMacro.data());
    cmd.append ( redirectTo.c_str() );
    if (system(cmd.data())) return 4;
    
    // run macro
    cmd = fXrdcpCmdRoot.data();
    cmd.append(" -b -q -l '");
    cmd.append(fXrdcpCmdRootMacro.data());
    cmd.append("(\"");
    cmd.append(from.data());
    cmd.append("\",\"");
    cmd.append(to.data());
    cmd.append("\");'");
    cmd.append ( redirectTo.c_str() );
    
    XrdDMLogDebugFull ( "DoCopyStdROOT : cmd is %s",cmd.data() );
    XrdDMLogGInfo ( "xrddm [%s] %s",fFileNameFrom.c_str(),cmd.data());
    
    if (system(cmd.data())) return 5;
    
    XrdDMLogDebugSilent ( "DoCopyStdROOT : retrun retValCpStd %d",retValCpStd );
    return retValCpStd;
}


int XrdDownloadManagerBase::DoCopyPre ( string from, string to ) {
    XrdDMLogDebugFull ( "DoAuthenticate(%d) %s %s",fDoAuthenticate,from.c_str(),to.c_str() );
    return DoAuthenticate ( false );
}

int XrdDownloadManagerBase::DoCopyWithType ( XrdDownloadManagerBase::EInputTypes_t type, string from, string to ) {
    XrdDMLogDebugFull ( "DoCopyWithType with type %d %s %s ",type,from.c_str(),to.c_str() );

    switch ( type ) {
    case kStdXrdcp :
        XrdDMLogDebugFull ( "DoCopyStd %d %s %s ",type,from.c_str(),to.c_str() );
        return DoXrdCp ( from,to );
    case kStdXrdcpGR :
        XrdDMLogDebugFull ( "DoCopyStd %d %s %s ",type, GetXrdGRPath ( from ).c_str(),to.c_str() );
        return DoXrdCp ( GetXrdGRPath ( from ),to );
    case kStdRootMacroCp :
        XrdDMLogDebugFull ( "DoCopyStdROOT %d %s %s ",type, GetXrdGRPath ( from ).c_str(),to.c_str() );
        return DoCopyStdROOT ( from ,to );
    default:
        XrdDMLogGWarning ( "Source type '%d' is not supported in this mode!!! Skipping ....",type );
        break;
    }
    return 1;
}


int XrdDownloadManagerBase::DoCopyPost ( string from, string to ) {

    if ( ( from.empty() ) || ( to.empty() ) ) return 0;

    return 0;
}

int XrdDownloadManagerBase::DoXrdCp ( string from, string to ) {

    if ( from.compare ( 0,7,"root://" ) ) {
        XrdDMLogWarning ( "%s doesn't start with 'root://' !!! Skipping ...",from.c_str() );
        return 1;
    }

//     char str[512];
    string redirectTo;
    if ( ( !fCurrentLogFileName.empty() ) && ( fLogDM ) ) {
        redirectTo.append ( ">> " );
        redirectTo.append ( fCurrentLogFileName.c_str() );
        redirectTo.append ( " 2>&1" );
    }

    string str2 = "echo \"";
    str2.append ( from.c_str() );
    str2.append ( " " );
    str2.append ( to.c_str() );
    str2.append ( "\"" );
    str2.append ( redirectTo.c_str() );
//     sprintf ( str2,"echo \"%s %s\" %s",from.c_str(),to.c_str(),redirectTo.c_str() );
    system ( str2.c_str() );

    string stried;
    if ( !fXrdcpCmdCn.empty() ) {
        stried = "-OStried=+";
        stried.append ( fXrdcpCmdCn.c_str() );
    }
    XrdDMLogDebugSilent ( "DoXrdCp : %s %s %s %s %s %s",XrdCpCmd().c_str(),fXrdcpCmdOptions.c_str(),stried.c_str(),from.c_str(),to.c_str(),redirectTo.c_str() );
//     XrdDMLogGInfo ( "%s %s %s",from.c_str(),to.c_str(),redirectTo.c_str() );
    XrdDMLogGInfo ( "xrddm [%s] xrdcp %s %s",fFileNameFrom.c_str(),from.c_str(),redirectTo.c_str() );
    XrdDMLogInfo ( "xrdcp %s",from.c_str() );


    string str = "";
    str.append ( XrdCpCmd().c_str() );
    str.append ( " -f " );
    str.append ( fXrdcpCmdOptions.c_str() );
    str.append ( " " );
    str.append ( from.c_str() );
    str.append ( " " );
    str.append ( to.c_str() );
    str.append ( " " );
    str.append ( redirectTo.c_str() );
//     sprintf ( str,"%s %s %s %s %s",XrdCpCmd().c_str(),fXrdcpCmdOptions.c_str(),from.c_str(),to.c_str(),redirectTo.c_str() );

    int retVal = system ( str.c_str() );
    XrdDMLogDebugSilent ( "DoXrdCp : retrun %d",retVal );
    return retVal;
}

int XrdDownloadManagerBase::FillListOfFileNamesFrom ( string fname ) {

    fListOfFileNamesFrom.push_back ( fname );
    PrintListOfFileNamesFrom();
    return 0;
}

void XrdDownloadManagerBase::PrintListOfFileNamesFrom() {
    unsigned int ii;
    for ( ii=0; ii < fListOfFileNamesFrom.size(); ii++ )
        XrdDMLogDebugFull ( "PrintListOfFileNamesFrom : %s",fListOfFileNamesFrom[ii].c_str() );
}



void XrdDownloadManagerBase::RemovingCopyProcessLogFile() {
    if ( ( fRemoveLogAfterSuccessCopy ) && ( !fCurrentLogFileName.empty() ) ) {
        string rmcmd ( "rm -fR " );
        rmcmd.append ( fCurrentLogFileName.c_str() );
        if ( fRemoveLogDirectoryAfterSuccessCopy ) {
            rmcmd.erase ( rmcmd.find_last_of ( "/" ),rmcmd.length() );
            rmcmd.append ( "/" );
        }
        XrdDMLogDebugSilent ( "Doing '%s', because copy was with retval 0 ...",rmcmd.c_str() );
        int rmRetVal = system ( rmcmd.c_str() );
        XrdDMLogDebugMedium ( "'%s' with rmRetVal %d ...",rmcmd.c_str(),rmRetVal );
    }
}

int XrdDownloadManagerBase::ReadConfigFile ( string filename ) {
    XrdDMLogDebugFull ( "virtual ReadConfigFile : Config file is %s",filename.c_str() );

    fstream file ( filename.c_str(), ios::in );
    if ( !file.is_open() ) {
        XrdDMLogGError ( "Error opening config file %s !!!",filename.c_str() );
        XrdDMLogError ( "Error opening config file %s !!!",filename.c_str() );
        return -1;
    }

    const short n = 256;
    char char_str[n];
    string str, var, val;
    size_t found;
    while ( file.getline ( char_str, n ) ) {
        str = char_str;
        if ( str.substr ( 0, 5 ).compare ( "xrddm" ) )
            continue;
        found = str.find ( "xrddm" );
        if ( found != string::npos ) {
            found = str.find_first_of ( "=" );
            var = str.substr ( 0, found );
            val = str.substr ( found + 1, str.length() );
            found = val.find ( "\"" );
            if ( found != string::npos ) {
                val.replace ( 0, 1, "" );
                val.replace ( val.length() - 1, 1, "" );
            }

            if ( !SetConfigOptions ( var, val ) )
                XrdDMLogDebugFull ( "ReadConfigFile : var=%s  val=%s",var.c_str(),val.c_str() );
        }

    }
    file.close();

    return 0;
}

int XrdDownloadManagerBase::SetConfigOptions ( string var, string val ) {

    if ( var.compare ( "xrddm.XrdOptions" ) == 0 ) {
        XrdDMLogDebugMedium ( "SetConfigOptions %s : %s",var.c_str(),val.c_str() );
        SetXrdcpOptions ( val );
        return 0;
    } else  if ( var.compare ( "xrddm.GlobalRedirector" ) == 0 ) {
        XrdDMLogDebugMedium ( "SetConfigOptions %s : %s",var.c_str(),val.c_str() );
        SetGlobalRedirectorName ( val );
        return 0;
    } else  if ( var.compare ( "xrddm.ROOTCpMacro" ) == 0 ) {
        XrdDMLogDebugMedium ( "SetConfigOptions %s : %s",var.c_str(),val.c_str() );
        SetXrdcpCmdRootMacro ( val );
    return 0;
    } 
    return -1;
}

int XrdDownloadManagerBase::InitLogFile() {


    if ( !fLogDM ) {
        fLogDirectory = "/tmp";
        fCurrentLogFileName = "";
        return 0;

    }

    string logfilenametmp = GetXrdFilename ( fFileNameFrom.c_str() );
    XrdDMLogDebugMedium ( "fLogDirectory %s ...",fLogDirectory.c_str() );

    string logfile ( fLogDirectory.c_str() );
    logfile += logfilenametmp.c_str();

    XrdDMLogDebugMedium ( "Creating log direcotry %s ...",logfile.c_str() );
    string mkdirStr ( "mkdir -p " );
    mkdirStr.append ( logfile.c_str() );
    mkdirStr.append ( " > /dev/null 2>&1" );
    int mkdirRetVal = system ( mkdirStr.c_str() );
    if ( mkdirRetVal ) {
        XrdDMLogGError ( "Direcotry %s was created with return value %d...",logfile.c_str(),mkdirRetVal );
        XrdDMLogInfo ( "Log sirectory is set to /tmp ..." );
        fLogDirectory = "/tmp";
    }

    logfile.append ( "/xrddm_" );
    time_t mytime;
    time ( &mytime );
    struct tm * timeinfo = localtime ( &mytime );
    char buffer [80];
    strftime ( buffer,80,"%Y%m%d%H%M%S.log",timeinfo );
    logfile.append ( buffer );

    // TODO check permition

    fCurrentLogFileName = logfile;
    if ( fLogDM ) {
        if ( !fCurrentLogFileName.empty() ) {
            fLogDM->SetFile ( fCurrentLogFileName.c_str() );
            XrdDMLogDebugSilent ( "Log file is %s ...",fCurrentLogFileName.c_str() );
        } else {
            XrdDMLogDebugSilent ( "No Log File ... " );
        }
    }


    return 0;
}
string XrdDownloadManagerBase::GetXrdType ( string xrdfilename ) {
    char * pch;
    pch = strtok ( ( char* ) xrdfilename.c_str(),":" );
    const char * type = ( const char* ) pch;
    if ( !strcmp ( type,"root" ) ) return "root";
    else if ( !strcmp ( type,"alien" ) ) return "alien";

    return "";
}

string XrdDownloadManagerBase::GetXrdHost ( string xrdfilename ) {
    char * pch;

    if ( !strcmp ( GetXrdType ( xrdfilename ).c_str(),"root" ) ) {
        xrdfilename.erase ( 0,7 );
        pch = strtok ( ( char* ) xrdfilename.c_str(),":" );
        return ( const char* ) pch;
    } else if ( !strcmp ( GetXrdType ( xrdfilename ).c_str(),"alien" ) )
        return "";

    return "";
}

string XrdDownloadManagerBase::GetXrdPort ( string xrdfilename ) {
    char * pch;
    string tmp ( GetXrdType ( xrdfilename ) );
    tmp.append ( "://" );
    tmp.append ( GetXrdHost ( xrdfilename ) );

    if ( !strcmp ( GetXrdType ( xrdfilename ).c_str(),"root" ) ) {
        xrdfilename.erase ( 0,tmp.length() +1 );
        if ( xrdfilename.find_first_of ( '/' ) ) return "1094";
        pch = strtok ( ( char* ) xrdfilename.c_str(),"/" );
        return ( const char* ) pch;
    } else if ( !strcmp ( GetXrdType ( xrdfilename ).c_str(),"alien" ) )
        return "";

    return "1094";
}

string XrdDownloadManagerBase::GetXrdFilename ( string xrdfilename ) {

    string tmp ( xrdfilename );
    if ( !strcmp ( GetXrdType ( xrdfilename ).c_str(),"root" ) ) {
        tmp.erase ( 0,tmp.find_first_of ( "/" ) +1 );
        tmp.erase ( 0,tmp.find_first_of ( "/" ) +1 );
        tmp.erase ( 0,tmp.find_first_of ( "/" ) +1 );
        tmp.erase ( 0,tmp.find_first_of ( "/" ) );
    } else if ( !strcmp ( GetXrdType ( xrdfilename ).c_str(),"alien" ) ) {
        tmp.erase ( 0,8 );
    }

    return tmp.c_str();
}

string XrdDownloadManagerBase::GetXrdGRPath ( string xrdfilename ) {
    if ( fGlobalRedirectorName.empty() ) {
        XrdDMLogDebugSilent ( "GR is not set, path is %s",xrdfilename.c_str() );
        return xrdfilename;
    }
    string fromWithGR ( "root://" );
    fromWithGR.append ( fGlobalRedirectorName.c_str() );
    fromWithGR.append ( "/" );
    fromWithGR.append ( GetXrdFilename ( xrdfilename.c_str() ) );
    XrdDMLogDebugFull ( "GR path is %s",fromWithGR.c_str() );
    return fromWithGR;

}


bool XrdDownloadManagerBase::IsFileNameValid ( string filename ) {
    if ( !strcmp ( GetXrdType ( filename ).c_str(),"root" ) ) return true;
    if ( !strcmp ( GetXrdType ( filename ).c_str(),"alien" ) ) return true;
    return false;
}


void XrdDownloadManagerBase::DoXrdcpInLogFile ( bool b, int debugLevel, string inputfile ) {
    delete fLogDM;
    if ( b ) {
        fLogDM =  new XrdDownloadManagerLog;
        if ( !inputfile.empty() ) {
            fFileNameFrom = inputfile;
            InitLogFile();
        }
        fLogDM->SetDebug ( debugLevel );

    } else {
        fLogDM = 0;
    }
}

int XrdDownloadManagerBase::TestZipFile ( string from, string to ) {

//     sleep(1);
    string redirectTo;
    if ( ( !fCurrentLogFileName.empty() ) && ( fLogDM ) ) {
        redirectTo.append ( ">> " );
        redirectTo.append ( fCurrentLogFileName.c_str() );
        redirectTo.append ( " 2>&1" );
    }

//     char str[512];
    string str;
    int retValZipTest = 0;
    if ( fDoZipTest ) {

        if ( !from.compare ( from.length()-4,from.length(),".zip" ) ) {
            XrdDMLogDebugSilent ( "Testing zip file '%s' ...",to.c_str() );
            if ( fZipCmd.empty() ) {
                XrdDMLogWarning ( "Command zip was not found at compilation time !!!" );
                return 0;
            }


            XrdDMLogDebugSilent ( "TestZipFile : %s -T %s %s",fZipCmd.c_str(),to.c_str(),redirectTo.c_str() );
            str=fZipCmd.c_str();
            str.append ( " -T " );
            str.append ( to.c_str() );
            str.append ( " " );
            str.append ( redirectTo.c_str() );
//             sprintf ( str,"%s -T %s %s",fZipCmd.c_str(),to.c_str(),redirectTo.c_str() );
            retValZipTest = system ( str.c_str() );
            if ( retValZipTest ) {
                XrdDMLogGError ( "xrddm [%s] Zip test of '%s' retValZipTest is %d ...",from.c_str(),to.c_str(),retValZipTest );
                XrdDMLogError ( "Zip test of '%s' retValZipTest is %d ...",to.c_str(),retValZipTest );
            } else {
                XrdDMLogInfo ( "Zip test of '%s' retValZipTest is %d ...",to.c_str(),retValZipTest );
                XrdDMLogGInfo ( "xrddm [%s] Zip test of '%s' retValZipTest is %d ...",from.c_str(),to.c_str(),retValZipTest );
            }
        }

    }

    if ( retValZipTest ) {
        str="rm -f ";
        str.append ( to.c_str() );
        str.append ( " " );
        str.append ( redirectTo.c_str() );
        XrdDMLogDebugSilent ( "Doing '%s', because retValZipTest is %d ...",str.c_str(),retValZipTest );
        int retValRm = system ( str.c_str() );
        XrdDMLogDebugSilent ( "Zip test of '%s' retValRm is %d ...",str.c_str(),retValRm );
    }


    return retValZipTest;
}

XrdDownloadManagerBase::EInputTypes_t XrdDownloadManagerBase::GetInputTypeId ( string inputTypeString ) {
    if ( !strcmp ( inputTypeString.c_str(),"std" ) ) {
        return kStdXrdcp;
    } else if ( !strcmp ( inputTypeString.c_str(),"stdgr" ) ) {
        return kStdXrdcpGR;
    } else if ( !strcmp ( inputTypeString.c_str(),"stdroot" ) ) {
        return kStdRootMacroCp;
    } else {
        XrdDMLogGWarning ( "Source type '%s' is not supported in this mode!!! Skipping ....",inputTypeString.c_str() );
    }
    return kStdXrdcp;
}


// void XrdDownloadManagerBase::FindAndReplaceString ( string &source, const string find, string replace ) {
//
//     size_t j;
//     for ( ; ( j = source.find ( find ) ) != string::npos ; ) {
//         source.replace ( j, find.length(), replace );
//     }
// }
// kate: indent-mode cstyle; space-indent on; indent-width 4;
